package com.xiaozhou.controller;

import com.zhipu.oapi.ClientV4;
import com.zhipu.oapi.service.v4.api.VideosClientApiService;
import com.zhipu.oapi.service.v4.videos.VideoCreateParams;
import com.zhipu.oapi.service.v4.videos.VideosResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shhzhou
 * @description:  文生视频大模型 例子  (ai生成的视频不好用，穿墙，透图，视频十分魔性)
 * @date 2024/10/31 16:43
 */
@RestController
@RequestMapping("/video")
public class VideoController {
    @Autowired
    private ClientV4 clientV4;

    /**
     * @return
     * @return com.zhipu.oapi.service.v4.videos.VideosResponse
     * @Author xiaozhou
     * @Description 文生视频接口   "id": "621217294747395139157395086137004915"
     * @Date 16:59 2024/10/31
     * @Param message
     */
    @GetMapping("/model")
    public VideosResponse model(String message) {
        VideoCreateParams videoCreateParams = VideoCreateParams.builder()
                .model("cogvideox")
                .prompt(message)
                .build();

        VideosResponse apply = new VideosClientApiService(clientV4.getConfig().getHttpClient(), clientV4.getConfig().getBaseUrl())
                .videoGenerations(videoCreateParams)
                .apply(clientV4);
        return apply;
    }

    /**
     * @Author xiaozhou
     * @Description 图生视频接口      "id": "621217294747395139157395326655380740"
     * @Date 17:13 2024/10/31
     * @Param message
     * @return
     * @return com.zhipu.oapi.service.v4.videos.VideosResponse
     */
    @GetMapping("/modelByImage")
    public VideosResponse modelByImage(String message) {
        //TODO  图片地址
        String imageUrl = "https://aigc-files.bigmodel.cn/api/cogview/2024103116353045dd8391f64540ed_0.png";

        VideoCreateParams videoCreateParams = VideoCreateParams.builder()
                .model("cogvideox")
                .imageUrl(imageUrl)
                .build();

        VideosResponse apply = new VideosClientApiService(clientV4.getConfig().getHttpClient(), clientV4.getConfig().getBaseUrl())
                .videoGenerations(videoCreateParams)
                .apply(clientV4);
        return apply;
    }


    /**
     * @return
     * @return com.zhipu.oapi.service.v4.videos.VideosResponse
     * @Author xiaozhou
     * @Description 视频结果查询接口
     * @Date 17:00 2024/10/31
     * @Param message
     */
    @GetMapping("/result")
    public VideosResponse result(String id) {
        VideoCreateParams videoCreateParams = VideoCreateParams.builder()
                .id(id)
                .build();

        VideosResponse apply = new VideosClientApiService(clientV4.getConfig().getHttpClient(), clientV4.getConfig().getBaseUrl())
                .videoGenerationsResult(videoCreateParams)
                .apply(clientV4);
        return apply;
    }


}
